package com.cloud.cmt.usermanage.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.cloud.cmt.usermanage.base.BaseEntity;
import com.cloud.cmt.usermanage.entity.eenum.Gender;
import com.cloud.cmt.usermanage.entity.eenum.JobStatus;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.NotBlank;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.validation.constraints.Pattern;
import java.util.Date;

/**
 * Created by Administrator on 2017/10/25.
 */
@Entity
@Data
public class Employee extends BaseEntity<Long>{

    @JsonProperty("tenant_id")
    @JSONField(name = "tenant_id")
    @ApiModelProperty(name = "tenant_id", notes = "租户", example = "1")
    private String tenantId;

    @JsonProperty("employee_num")
    @JSONField(name = "employee_num")
    @ApiModelProperty(name = "employee_num", notes = "工号", example = "0001")
    @NotBlank(message ="工号字段不能为空",groups=SAVE.class)
    private String employeeNum;

    @JsonProperty("name")
    @JSONField(name = "name")
    @ApiModelProperty(name = "name", notes = "姓名", example = "刘东")
    @NotBlank(message ="姓名字段不能为空",groups=SAVE.class)
    private String name;

    @JsonProperty("sex")
    @JSONField(name = "sex")
    @Enumerated(EnumType.STRING)
    @ApiModelProperty(name = "sex", notes = "性别", example = "male")
    private Gender sex;

    @JsonProperty("phone")
    @JSONField(name = "phone")
    @ApiModelProperty(name = "phone", notes = "电话", example = "13783654321")
    @Pattern(regexp = "^((13[0-9])|(15[^4,\\D])|(17[^4,\\D])|(18[^4,\\D]))\\d{8}$", message = "手机号格式不正确",groups=SAVE.class)
    private String phone;

    @JsonProperty("region")
    @JSONField(name = "region")
    @ApiModelProperty(name = "region", notes = "区域", example = "杭州")
    private String region;

    @JsonProperty("status")
    @JSONField(name = "status")
    @Enumerated(EnumType.STRING)
    @ApiModelProperty(name = "status", notes = "状态", example = "working")
    private JobStatus status;

    @JsonProperty("photo")
    @JSONField(name = "photo")
    @ApiModelProperty(name = "photo", notes = "照片", example = "http://imgtu.5011.net/uploads/content/20170414/6256421492148399.jpg")
    private String photo;

    @JsonProperty("id_card")
    @JSONField(name = "id_card")
    @ApiModelProperty(name = "id_card", notes = "身份证", example = "330354187714158794")
    private String idCard;

    @JsonProperty("graduate_school")
    @JSONField(name = "graduate_school")
    @ApiModelProperty(name = "graduate_school", notes = "毕业学校", example = "浙江大学")
    private String graduateSchool;

    @JsonProperty("edu_background")
    @JSONField(name = "edu_background")
    @ApiModelProperty(name = "edu_background", notes = "学历", example = "博士")
    private String eduBackground;

    @JsonProperty("market")
    @JSONField(name = "market")
    @ApiModelProperty(name = "market", notes = "所属市场（多选）", example = "|1|2|3|")
    private String market;

    @JsonProperty("report_date")
    @JSONField(name = "report_date")
    @ApiModelProperty(name = "report_date", notes = "入职日期", example = "2017-10-27")
    private Date reportDate;

    @JsonProperty("leaving_date")
    @JSONField(name = "leaving_date")
    @ApiModelProperty(name = "leaving_date", notes = "离职日期", example = "2017-10-27")
    private Date leavingDate;

    @JsonProperty("id_card_photo")
    @JSONField(name = "id_card_photo")
    @ApiModelProperty(name = "id_card_photo", notes = "身份证照片/复印件照片\n", example = "http://imgtu.5011.net/uploads/content/20170414/6256421492148399.jpg")
    private String idCardPhoto;

    public interface SAVE{};

    //注意进行校验的方法要写成静态方法，否则会出现
    //TypeError: xxx is not a function 的错误
    public static boolean checkParams(String name,int age,String classes) {
        if(name!=null&&age>8&classes!=null)
        {
            return true;
        }
        else
        {
            return false;
        }

    }
}
